# Application modules
from imports import *

# Administrative Menu
class AdminOptions(webapp.RequestHandler):
  """Listing of administrative options"""
  def get(self):
    global admin_opts
    
    if not users.is_current_user_admin():
      return self.response.out.write("Unauthorized")
    
    # Extract links automatically
    parsed_opts = []; excl_opts = []
    for i in admin_opts:
      page_name = i[1].__name__
      if page_name not in excl_opts:
        parsed_opts.append({'url':i[0], 'name':page_name, 'doc':i[1].__doc__})
        excl_opts.append(page_name)
    
    path = os.path.join(os.path.dirname(__file__), 'admin.html')
    self.response.out.write(template.render(path, locals()))  


# Admin options Listing
admin_opts = [('/admin/options', AdminOptions), \
              ('/admin/', AdminOptions)]
    
# Run the application
application = webapp.WSGIApplication(admin_opts, debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()